import { Controller, Get, Post, Body, Query, Param, Put, Delete } from '@nestjs/common';
import { UsersService } from './users.service';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { CreateUserDto } from './dto/create-user.dto';

@ApiTags('用户管理')
@Controller('users')
export class UsersController {
  constructor(private readonly usersService: UsersService) {}

  /**
   * 获取所有用户
   */
  @ApiOperation({ summary: '查询所有用户' })
  @Get()
  async findAll(@Query() query): Promise<any> {
    console.log(query);
    return await this.usersService.findAll();
  }

  /**
   * 创建用户
   * @param user
   */
  @ApiOperation({ summary: '创建用户' })
  @Post()
  async create(@Body() user: CreateUserDto) {
    return await this.usersService.create(user);
  }

  /**
   * 更新指定用户
   * @param id
   * @param user
   */
  /**
   * 创建用户
   * @param user
   */
  @ApiOperation({ summary: '更新用户' })
  @Put(':id')
  async update(@Param('id') id, @Body() user): Promise<any> {
    console.log(id, user);
    return await this.usersService.updateById(id, user);
  }

  /**
   * 删除用户
   */
  @ApiOperation({ summary: '删除用户' })
  @Delete(':id')
  async remove(@Param('id') id): Promise<any> {
    return await this.usersService.remove(id);
  }

  /**
   * 获取指定用户
   */
  @ApiOperation({ summary: '获取指定用户' })
  @Get(':id')
  async findOne(@Param('id') id): Promise<any> {
    console.log(id, 'id');
    return await this.usersService.findById(+id);
  }
}
